package cn.icanci.loopstack.plugin.dalgen.config;

import cn.icanci.loopstack.plugin.dalgen.factory.PropertiesFactory;
import cn.icanci.loopstack.plugin.dalgen.model.ConfigurationInfoVO;

import java.io.IOException;

/**
 * 单例模式 -> 全局配置信息
 *
 * @author icanci
 * @since 1.0 Created in 2022/05/13 17:34
 */
public class GlobalConfig {

    // 配置信息
    private volatile static ConfigurationInfoVO CONFIGURATION_INFO = null;

    private GlobalConfig() {
    }

    /***
     * 获取全局配置
     * 单例模式 双重锁校验
     */
    public static ConfigurationInfoVO getGobleConfig(String path) {
        if (null == CONFIGURATION_INFO) {
            synchronized (GlobalConfig.class) {
                if (null == CONFIGURATION_INFO) {
                    try {
                        PropertiesFactory.loadProperties(path);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return CONFIGURATION_INFO;
    }

    /***
     * 获取全局配置
     * 单例模式 双重锁校验
     */
    public static ConfigurationInfoVO getGobleConfig() {
        return CONFIGURATION_INFO;
    }

    public static void setGlobalConfig(ConfigurationInfoVO config) {
        GlobalConfig.CONFIGURATION_INFO = config;
    }

}
